package com.demo.oauth2.server.services;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.ejb.Stateless;

import com.demo.oauth2.server.model.AplicacaoCliente;

@Stateless
public class AplicacaoAuthenticationService {

	private Map<String, AplicacaoCliente> mapClientId;
	
	@PostConstruct
	private void init() {
		
		this.mapClientId = new HashMap<String, AplicacaoCliente>();
		
		AplicacaoCliente myapp = new AplicacaoCliente();
		myapp.setId("outh2-demo-client-id");
		myapp.setNome("MyApp");
		this.mapClientId.put(myapp.getId(), myapp);
	}
	
	
	public boolean salvarRedirectURI(String clientId, String redirectURI) {
		
		AplicacaoCliente appCliente = this.mapClientId.get(clientId);
		
		if (appCliente == null) {
			return false;
		}
		else {
			appCliente.setUrlRedirect(redirectURI);
			return true;
		}
	}
	
	public boolean ehAplicacaoClienteCadastrada(String clientId) {
		return this.mapClientId.containsKey(clientId);
	}
	
}
